/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-02-24 17:24:34
 * @LastEditTime: 2024-02-25 09:20:36
 * @FilePath: /react-vite-admin/src/store/index.tsx
 */
import { createContext, useContext } from "react";
import User from "./user";
import Settings from "./settings";
import Tags from "./tags";
import Permissions from "./permissions";
//合并
class Store {
    user: User;
    settings: Settings;
    tags: Tags;
    permissions:Permissions;
    constructor() {
        this.user = new User;
        this.settings = new Settings;
        this.tags = new Tags;
        this.permissions = new Permissions;
    }
}

const rootStore = new Store();
//创建上下文对象，封装组件
const RootStoreContext = createContext(rootStore);

export const RootStoreProvider = (props: { children: JSX.Element }) => {
    return (
        <RootStoreContext.Provider value={rootStore}>
            {props.children}
        </RootStoreContext.Provider>
    )
}
//封装获取上下文对象数据的方法
export const useRootStore = () => {
    return useContext(RootStoreContext);
}